-- -*- mode: lua; -*-

-- This is a trivial example of a chain of random blocks. The output
-- of block N is connected to the seed of random block N+1.  The
-- system is constructed by hierarchically composing these blocks.
local utils = require("utils")

local rnd2 = bd.system {

   imports = {
      "stdtypes", "random",
   },

   blocks = {
      { name="rnd", type="ubx/random" },
   },

   configurations = {
      {	name="rnd", config = { min_max_config = {min=127, max=256} } }
   },
}


local rnd1 = bd.system {
   subsystems = {
      sub21 = utils.deepcopy(rnd2),
      sub22 = utils.deepcopy(rnd2),
   },

   blocks = {
      { name='trig', type="ubx/trig" },
      { name="rnd", type="ubx/random" },
   },

   configurations = {
      {	name="rnd", config = { min_max_config = {min=127, max=256} } },
      { name="trig", config = { chain0={
				   { b="#rnd", num_steps=1, measure=0 },
				   { b="#sub21/rnd", num_steps=1, measure=0 },
				   { b="#sub22/rnd", num_steps=1, measure=0 } } } }
   }
}

return bd.system
{
   imports = {
      "stdtypes", "random", "trig", "lfds_cyclic", "logger",
   },

   subsystems = {
      sub11 = utils.deepcopy(rnd1),
      sub12 = utils.deepcopy(rnd1),
   },

   blocks = {
      { name='trig', type="ubx/trig" },
      { name="rnd", type="ubx/random" },
   },

   configurations = {
      {	name="rnd", config = { min_max_config={min=1, max=2} } },
      {	name="sub11/rnd", config = { min_max_config={min=11, max=33} } },
      {	name="sub11/sub21/rnd", config = { min_max_config={min=11, max=44} } },
      { name="trig", config = { chain0={
				   { b="#rnd", num_steps=1, measure=0 },
				   { b="#sub11/trig", num_steps=1, measure=0 },
				   { b="#sub12/trig", num_steps=1, measure=0 } } } },

   },

   connections = {
      { src="rnd.rnd", tgt="sub11/rnd.seed" },
   },
}
